﻿using ZR.Model.Souvenir;
using ZR.Model.Souvenir.Dto;
using ZR.Service.Souvenir.IService;

namespace ZR.Admin.WebApi.Controllers.Souvenir
{
    [Route(("souvenir/product"))]
    public class ProductController : BaseController
    {
        private readonly IProductService _productService;

        public ProductController(IProductService productService)
        {
            _productService = productService;
        }
        
        [HttpPost("addProduct")]
        public async Task<IActionResult> AddProduct([FromBody] Product product)
        {
            // if (!Request.Content.IsMimeMultipartContent())
            // {
            //     throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            // }
            //
            // try
            // {
            //     var multipartMemoryStreamProvider = await Request.Content.ReadAsMultipartAsync();
            //     
            // }
            // catch (Exception e)
            // {
            //     System.Console.WriteLine(e);
            //     throw;
            // }
            
            return SUCCESS(await _productService.InsertProductAsync(product) > 0);
        }

        [HttpPut("updateProduct")]
        public async Task<IActionResult> UpdateProduct([FromBody] Product product)
        {
            return SUCCESS(await _productService.UpdateProductAsync(product) > 0);
        }
        
        [HttpDelete("deleteProduct/{productId}")]
        public async Task<IActionResult> DeleteProduct(int productId)
        {
            return SUCCESS(await _productService.DeleteProductAsync(productId) > 0);
        }
        
        [HttpPost("getProductWithPage")]
        public async Task<IActionResult> GetProductWithPage([FromBody] ProductQueryDto productQueryDto)
        {
            return SUCCESS(await _productService.SelectProductWithPageAsync(productQueryDto));
        }
        
        [HttpGet("getProductById/{productId}")]
        public async Task<IActionResult> GetProductById(int productId)
        {
            return SUCCESS(await _productService.SelectProductAsyncById(productId));
        }
    }
}